<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file="common/head" /}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form action="" id="form" class="layui-form" method="post">
            <input type="hidden" name="uid" value="{$uid|default=0}">

            <div class="layui-form-item">
                <label for="new_pwd" class="layui-form-label">
                    <span class="x-red">*</span>新密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" value="" id="new_pwd" name="new_pwd" required=""
                           lay-verify="pass" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="real_pwd" class="layui-form-label">
                    <span class="x-red">*</span>重复新密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" value="" id="real_pwd" name="real_pwd" required=""
                           lay-verify="pass" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>



            <div class="layui-form-item">
                <label for="ok" class="layui-form-label">
                </label>
                <button id="ok" class="layui-btn" lay-filter="add" lay-submit="">
                    立 即 修 改
                </button>
            </div>
        </form>
    </div>
</div>

<div id="idbox" style="display: none">

</div>
<script>layui.use(['form', 'layer'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({

            pass:[
                /^[\S]{6,20}$/
                ,'密码必须6到20位，且不能出现空格'
            ]

        });

        //监听提交
        form.on('submit(add)',
            function (data) {
                console.log(data.field);

                if(data.field.real_pwd!=data.field.new_pwd){
                    layer.alert('重复密码有误！', {
                        icon: 2
                    });
                    return false;
                }

                $.ajax({
                    type: "POST",
                    url: "{:url()}",
                    data: data.field,
                    success: function (result) {
                        if(result.code){
                            layer.alert(result.msg, {
                                icon: 6
                            });
                        }else{
                            layer.alert(result.msg, {
                                icon: 2
                            });
                        }
                    },
                    error: function (data) {
                        layer.alert(data.msg, {
                            icon: 2
                        });
                    }

                });
                return false;
            });


    });
</script>

</body>

</html>
